"""
关注加油站
"""
import os
import sys
import django
import base64

BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
print(BASE_DIR)
sys.path.insert(0, BASE_DIR)
os.environ['DJANGO_SETTINGS_MODULE'] = 'finance_c2c.settings'
django.setup()

from core.tl.client import TlAuth


def decrypt_mobile():
    tl_auth = TlAuth()
    # c = "ZVFjSEV4TzRERjl1L24rQmpUbUVTZmZsRStPRUhoUkoxdTlrVEY2eWxSbXlrb3VCMDJUeWxpL01LcFNYYmJoNXFpTm1WSnM3RE9RNGFiMzNOTTduMTdDdFhlZVkxSUhnNmc1c2JqSWNvRUNwaUFwTzNWNUY0T0IwYXZPMFZKem1OOVJsNUh1c21lYW1raHlWZGZaYWRicThHcDgwSlBzSVc2THp1a1JITGlBPQ=="
    # c = "V1A2alVTQ2NLRldrejRHeVMxY0pHR05abjJpc09hNHprcGNQRUpxa3Z0Mzc2OUluM1lkMnlBY0t3Y3NqNzFEZmg5NVJ0Ti92M2VVSFNleW9XczJMbFRqRkxNbG1qMTZjdXRrVldpSTdaWE1PVmpENFBNQnRhTGhqSUJteFVXdEpDSUZONzlDUkxQWDZEc2ZTUUNnMzdBR0dzcVZhL2hlckZEU3ZlMU1xOU9jPQ=="
    c = "YXNraE5QVmJqL1kxZmJIcGwzdnFPTTBkM1FQRDRZUUhlRVlwWldTNEdySjFoVnIrSjBEZDVQOEFEc2RrZmZWUzBhWkFZdkMwZmpLM0NQTUVlZDdRSGhsdmZaUVRwbmFURmRmdzZvTFZnMkVTRlZSVURGZWtHMkNMdW1rZi94WXZ4NkRSYzNwQzIyVzkvM3FIR2tkdTJWdVdMTkMxT2RSNmkwNXVvRkMxcmNBPQ=="
    d = "dGJxVXE2bmRncTlDK213V2JHTlQva0xqQzN6dFRNaEhDQzlPRTBUSnVGZDh3RXF6Tk9CN0pwR0tYd1NZRDRkR0pla1hsdnB6R1picHRVOXQ4Unk2S0MzblV1bmZwVnc3TU92RS81RW9ndjM2bEtQQzVhQzE2cjNIRm9sY0U1MGhFMlhQaUdzSmlhUnh1Z0tKdzRjQjlVZ2ZiTWRHYW9na2hGS2tqL3djcVV3PQ=="
    cipher_text = base64.urlsafe_b64decode(c)
    m = base64.b64decode(cipher_text)
    mobile = tl_auth.decrypt_with_rsa(m)
    print(mobile)


def to_verify():
    tl_auth = TlAuth()
    parameters = {
        "merchantCode": "hjy",
        "version": "1.0",
        "appId": "wx1234567890",
        "custCode": "10fc282919aa4c14a3bbfe1a036921ba",
        # "custPhone": "UHJwU1RyQzVQbm85dXFuS093WDBINGEyeHZRYlhiOTZMQnlhT1V5cUFKNmlxWHJMWWlBWDdaSlBqYnlzVXJjWTdmdU9KWkhOZTNxTGhFL1FCQXhRZDZOYjB4MHFxSmFZMTJpRkRkZG9QbVVCVHAwVnRRcklPYUJ5NnZ2UUpucEFvMjN1dnhleWVORDlPaHIxSXplL05WNlpONjg1eGl5eDM1QTl6STRyRTNrPQ==",
        "custPhone":"13012345678",
        "bankCode": "CMBC",
        "bankEntryCode": "43c4a61defbf486c89e6d7b0428b2a6e",
        "bankEntryType": "1",
        "senceCode": "928a4a965d0c4c4c8b298d5e4151dc1e"
    }

    parameters = {
        "merchantCode": "Kalaibao",
        "version": "1.0",
        "appId": "c8013932d6474d6e9b0e647c17f1a138",
        "custCode": "257eb6fccb3a48f29a1a1711b7af67f4",
        # "custPhone": "UHJwU1RyQzVQbm85dXFuS093WDBINGEyeHZRYlhiOTZMQnlhT1V5cUFKNmlxWHJMWWlBWDdaSlBqYnlzVXJjWTdmdU9KWkhOZTNxTGhFL1FCQXhRZDZOYjB4MHFxSmFZMTJpRkRkZG9QbVVCVHAwVnRRcklPYUJ5NnZ2UUpucEFvMjN1dnhleWVORDlPaHIxSXplL05WNlpONjg1eGl5eDM1QTl6STRyRTNrPQ==",
        "custPhone": "18612386233",
        "bankCode": "CMBC",
        "bankEntryCode": "6449a06377c24df7b55f91df3fda7a68",
        "bankEntryType": "1",
        "senceCode": "6e82dc049d464a2097f28d27085ce1f0"
    }

    base_sorted = ["merchantCode", "version", "appId", "custCode", "custPhone", "bankCode", "bankEntryCode",
                   "bankEntryType", "senceCode"]
    # signature = "YUx3Q1o2S0pXZkFYMXhrQzVwUWhZZjJmUGwxMWZlVjRXaGV2bkpMVlFqVFJHOUw5QlpQY0FyemRDR0cvMFhFVVROeitUZDAxZjdTSm0vOTlzVzNOSDVYSmcvR0x1MVRoOTV4Y3FaK1FtL1hraW8xSXNmWGpZYytKT3EzTm1HbHlXNWFyTTFjNzZjMTIwRHV2K0FFak50WDlYSlFqcUpWZmRQOEEzL2lndXR3PQ=="
    signature = "TlJqazN2NFRoOEdiWDJmZXNSWlIvYmhBOTZJMGdyUGFmVk5MT3FDbTFNeEllZUFQaVQ2WklCR0dYdmlhRVlvODREa3BLeSsxa2VwT2hKRU92Z2dhNHRVRzB2VjlpSng0OWZ3VERqcHBtaWYzblhNVVNSclkzRklveWYvTThrTmRQMS92QThEWnlrQURuRzFNQjYyMXRzam1IMDdoRWJPUkdMTVFNcU50R0ZNPQ=="
    source = tl_auth.get_source_add_key(parameters, base_sorted)
    print(source)
    verify_result = tl_auth.Oauth_verify_with_public_key(signature, source)
    print(verify_result)

if __name__ == '__main__':
    # to_verify()
    decrypt_mobile()
